$(function(){
   var data = {
		method: "GET",
		url:path+'/human-resource/stff-train',
		columns: [{
			checkbox: true,
		}, {
			field: 'trainParticipantsId',
			visible: false
		}, {
			field: 'trainId',
			title: '培训项目编号',
			visible: false
		}, {
			field: 'trainStartDate',
			title: '开始日期'
		}, {
			field: 'trainEndDate',
			title: '结束日期'
		}, {
			field: 'trainType',
			title: '培训类型',
			searchable:true
		}, {
			field: 'trainDescription',
			title: '培训内容描述'
		}, {
			field: 'trainShouldPeoples',
			title: '应到参加人数'
		}, {
			field: 'trainActualPeoples',
			title: '实到参加人数'
		}, {
			field: 'trainAddress',
			title: '培训地点'
		}, {
			field: 'trainParticipateEmployee',
			title: '培训人员',
			formatter: function(value, row, index) {
				if (value == "allStaff") {
					return '<span class="layui-badge layui-bg-blue">全体员工</span>';
				} else if (value == "allMan") {
					return '<span class="layui-badge layui-bg-green">全体男员工</span>';
				} else if (value == "allGirl") {
					return '<span class="layui-badge layui-bg-orange">全体女员工</span>';
				} else {
					return '<span class="layui-badge">自行选着</span>';
				}
			}
		},{
			field: 'trainStatus',
			title: '培训状态',
			formatter: function(value, row, index) {
				if (value == 1) {
					return '<span class="layui-badge layui-bg-blue">未开始</span>';
				}else if(value == 2) {
					return '<span class="layui-badge layui-bg-green">进行中</span>';
				} else if (value == 3) {
					return '<span class="layui-badge layui-bg-orange">已结束</span>';
				} else {
					return '<span class="layui-badge">重新安排</span>';
				}
			},
			searchable:true
		}],	
		sortable: true,
        sortOrder: "asc",
        search: false
   }
   
   var param = [{text:"日期范围",name:"dateScope",type:"text",verify:""},{text:"培训状态",name:"empEducation",type:"select",option:[{key:"1",value:"未开始"},{key:"2",value:"进行中"},{key:"3",value:"已结束"},{key:"4",value:"重新安排"}]},{text:"培训地点",name:"empNativePlace",type:"text",verify:"chineseStr"}];
   
   renderTable(cTable,data);
   
   createQueryPanel(param);
   
   laydate.render({
	   elem: '[name="dateScope"]'
	   ,range: true
   });
   
   form.render();
})

$("#add_btn").click(function(){
    openOperateWindow({
    	title: "添加培训项目",
    	url: "/admin/enterpriseManagement/humanResources/staffTrain/staff-train-add.jsp"
    })
})

$("#remove_btn").click(
	function(){
		requestRemoveData("trainId","/human-resource/staff-train");
	}
)

$("#modify_btn").click(function(){
	var rows = cTable.bootstrapTable('getSelections');
	if(rows.length==1){
		var index = layer.open({
			type: 2,
			area : ['1000px','600px'],
			content: path+'/admin/enterpriseManagement/humanResources/staffTrain/staff-train-update.jsp',
			maxmin: true,
			success: function (layero, index) {
				//通过layer提供的方法获取iframe窗口对象
				var body = layer.getChildFrame('body', index);
				//得到iframe页的窗口对象，执行iframe页的方法：iframeWin.method();
                var iframeWin = window[layero.find('iframe')[0]['name']]; 
                //获取页面的内容
                var iframeWindow = layero.find('iframe')[0].contentWindow;
                for (var Key in rows[0]){
                	if(Key==="trainParticipateEmployee"){
                		break;
                	}
                	body.find("input[name='"+Key+"']").val(rows[0][Key]);
                }
                //根据当前选中的记录来根据value判断哪个是需要默认选中的radio
                body.find("input[name='trainingStatusRadio'][value='"+rows[0].trainStatus+"']").attr("checked",true); 
                //other是执行选择的意思,在数据库表中有记录该状态
                if(rows[0].trainParticipateEmployee!="other"){
                	//找到对应当前记录的radio,加上checked属性
                	body.find("input[name='trainParticipateEmployee'][value='"+rows[0].trainParticipateEmployee+"']").attr("checked",true); 
                	body.find("#selectStaff").addClass("layui-btn-disabled");
                	body.find("#selectStaff").attr("disabled",true);
                }else{
                	//调用子页面中的赋值函数,转换成一个数组传给子页面
                	iframeWin.setSelectStaffIds(rows[0].trainParticipantsId.split(''));
                	iframeWin.setRadioDisabled();
                }
                //重新渲染radio
                iframeWindow.layui.form.render('radio'); 
            },
            end:function(){
            	cTable.bootstrapTable('refresh');
            }
		});
	}else{
		fixedAlert("请勾选需要修改的记录,一次只能修改一条!",0);
	}
})